/********************************************************/
/*	Copyright (C) 2016 Gong Li Bin			*/
/*	Project:	GlbCloud			*/
/*	Author:		gong_libin			*/
/*	Date:		2012_01_12			*/
/*	File:		MrMd5.h				*/
/********************************************************/

#ifndef _MRMD5_H
#define	_MRMD5_H

#include "MrGlobal.h"

#define	MR_MD5					16

#define	F1(x, y, z)				(z ^ (x & (y ^ z)))
#define	F2(x, y, z)				F1(z, x, y)
#define	F3(x, y, z)				(x ^ y ^ z)
#define	F4(x, y, z)				(y ^ (x | ~z))

#define	MRMD5STEP(f, w, x, y, z, data, s)	(w += f(x, y, z) + data, w = w << s | w >> (32 - s), w += x)

class CMrMd5
{
public:
	CMrMd5();
	virtual ~CMrMd5();

	void MrMd5Init();
	void MrMd5Final(UCHAR digest[16]);
	void MrMd5Update(UCHAR* puszBuf, UINT uiLen);
	void MrMd5Run(UCHAR* puszBuf, UINT uiLen, UCHAR digest[16]);

private:
	UINT m_uiBuf[4];
	UINT m_uiBits[2];
	UCHAR m_ucIn[64];

	void MrMd5Transform(UINT buf[4], UINT in[16]);
	void MrMd5ByteReverse(UCHAR* puszBuf, UINT uiLongs);

};

#endif /* _MRMD5_H */
